﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Windows.Forms;
using mmoss.orm;
using mmoss.application.classes;
using mmoss.configuration;


namespace mmoss.application
{
    public partial class Login : Form
    {
        public User UserSuccess;
        public Login()
        {
            this.Load += new EventHandler(Login_Load);
            InitializeComponent();
            lblError.Text = "";
        }

        void Login_Load(object sender, EventArgs e)
        {
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            
            //bounce against the orm for login credentials
            User l_user = dbConn.db.Users.ValidateLogin(txtUsername.Text.Trim(), txtPassword.Text.Trim());
            if (l_user == null)
            {
                lblError.Text = "Username/Password not valid.  Please try again";
            }
            else
            {
                Default.CurrentUser = l_user;
                UserSuccess = l_user;
                //check for multiple mmcs here
                Default.CurrentLocation = l_user.UserPermissionsXrefs.Where(p => p.Location.LocationType.locationTypeID == 1).First().Location;
                //todo
                this.Close();
            }
        }
    }

}
